home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / xgadgets.pas < prev    next >
Pascal/Delphi Source File  |  1991-12-18  |  3KB  |  112 lines

  1. {********************************************************************}
  2. {                                                                    }
  3. { Author:     Donn Ault                                              }
  4. { Date:       12/18/91                                               }
  5. { Purpose:    Extend clock view to show am/pm                        }
  6. {             Extend heap view to include commas (more readable)     }
  7. { Copyright:  Donated to the public domain                           }
  8. {                                                                    }
  9. { Notes:                                                             }
  10. {  + In your main program you will need more space for the expanded  }
  11. {    views.  The old clock uses 9 characters while the new           }
  12. {    clock uses 12.  The old heap viewer uses 9 while the new one    }
  13. {    uses 13.  Change the R.B.X occordingly.                         }
  14. {                                                                    }
  15. {********************************************************************}
  16.  
  17. unit xgadgets;
  18.  
  19. {$F+,O+,S-,D-}
  20.  
  21. interface
  22.  
  23. uses Dos, Objects, Views, App, gadgets;
  24.  
  25. type
  26.   PXHeapView = ^TXHeapView;
  27.   TXHeapView = object (THeapView)
  28.     Procedure Draw; Virtual;
  29.     Function  Comma ( N : LongInt ) : String;
  30.   End;
  31.  
  32.   PXClockView = ^TXClockView;
  33.   TXClockView = Object (TClockView)
  34.     am : Char;
  35.     Function FormatTimeStr (h,m,s : word) : String; Virtual;
  36.     Procedure Draw; Virtual;
  37.   End;
  38.  
  39. implementation
  40.  
  41. uses Drivers;
  42.  
  43. Function TXHeapView.Comma ( n : LongInt) : String;
  44. Var num, loc : Byte;
  45.     s : String;
  46.     t : String;
  47. Begin
  48.   Str (n,s);
  49.   Str (n:Size.X,t);
  50.  
  51.   num := length(s) div 3;
  52.   if (length(s) mod 3) = 0 then dec (num);
  53.  
  54.   delete (t,1,num);
  55.   loc := length(t)-2;
  56.  
  57.   while num > 0 do
  58.   Begin
  59.     Insert (',',t,loc);
  60.     dec (num);
  61.     dec (loc,3);
  62.   End;
  63.  
  64.   Comma := t;
  65. End;
  66.  
  67. procedure TXHeapView.Draw;
  68. var
  69.   S: String;
  70.   B: TDrawBuffer;
  71.   C: Byte;
  72.  
  73. begin
  74.   OldMem := MemAvail;
  75.  
  76.   S := Comma (OldMem);
  77.   C := GetColor(2);
  78.   MoveChar(B, ' ', C, Size.X);
  79.   MoveStr(B, S, C);
  80.   WriteLine(0, 0, Size.X, 1, B);
  81. end;
  82.  
  83. procedure TXClockView.Draw;
  84. var
  85.   B: TDrawBuffer;
  86.   C: Byte;
  87. begin
  88.   C := GetColor(2);
  89.   MoveChar(B, ' ', C, Size.X);
  90.   MoveStr(B, TimeStr + ' '+am+'m', C);     { Modified line }
  91.   WriteLine(0, 0, Size.X, 1, B);
  92. end;
  93.  
  94. Function TXClockView.FormatTimeStr (h,m,s: Word) : String;
  95. Begin
  96.   if h = 0 then
  97.   Begin
  98.     h := 12;
  99.     am := 'a';
  100.   End
  101.   Else if h > 12 then
  102.   Begin
  103.     dec (h,12);
  104.     am := 'p';
  105.   End
  106.   Else am := 'a';
  107.   FormatTimeStr := TClockView.FormatTimeStr (h,m,s);
  108. End;
  109.  
  110. End.
  111.  
  112.